package com.mine.modules.vm.controller;


import com.mine.common.domain.vo.Result;
import com.mine.modules.vm.domain.dto.BatchAddSensorGroupDto;
import com.mine.modules.vm.domain.query.SensorQuery;
import com.mine.modules.vm.service.IVmSensorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 传感器 前端控制器
 * </p>
 *
 * @author xujf
 * @since 2024-11-08
 */
@Api(tags = "传感器管理")
@RestController
@RequestMapping("/vm/sensor")
@RequiredArgsConstructor
public class VmSensorController {

    private final IVmSensorService vmSensorService;

    @ApiOperation(value = "分页获取传感器列表", notes = "分页获取传感器列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<?> queryPageList(SensorQuery sensorQuery) {
        return vmSensorService.queryPageList(sensorQuery);
    }

    @ApiOperation(value = "分页获取传感器-当前设备未绑定的", notes = "分页获取传感器-当前设备未绑定的")
    @RequestMapping(value = "/pageListNotInDevice", method = RequestMethod.GET)
    public Result<?> pageListNotInDevice(SensorQuery sensorQuery) {
        return vmSensorService.queryPageListNotInDevice(sensorQuery);
    }

    @ApiOperation(value = "批量设置传感器显示分组", notes = "批量设置传感器显示分组")
    @RequestMapping(value = "/batchAddSensorGroup", method = RequestMethod.POST)
    public Result<?> batchAddSensorGroup(BatchAddSensorGroupDto addSensorGroupDto) {
        return vmSensorService.batchAddSensorGroup(addSensorGroupDto);
    }

    @ApiOperation(value = "按照显示分组返回layer下传感器列表", notes = "按照显示分组返回layer下传感器列表")
    @RequestMapping(value = "/sensorGroupListByLayerId", method = RequestMethod.GET)
    public Result<?> sensorGroupListByLayerId(@RequestParam String layerId) {
        return vmSensorService.sensorGroupListByLayerId(layerId);
    }

    @ApiOperation(value = "修改传感器别名-id", notes = "修改传感器别名-id")
    @RequestMapping(value = "/editSensorAliasById", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "传感器id"),
            @ApiImplicitParam(name = "alias", value = "传感器别名")})
    public Result<?> editSensorAliasById(@RequestParam String id, @RequestParam String alias) {
        return vmSensorService.editSensorAliasById(id, alias);
    }

    @ApiOperation(value = "修改传感器别名-code", notes = "修改传感器别名-code")
    @RequestMapping(value = "/editSensorAliasByCode", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "传感器id"),
            @ApiImplicitParam(name = "alias", value = "传感器别名")})
    public Result<?> editSensorAliasByCode(@RequestParam String code, @RequestParam String alias) {
        return vmSensorService.editSensorAliasByCode(code, alias);
    }

    @ApiOperation(value = "分页历史数据查询", notes = "分页历史数据查询")
    @RequestMapping(value = "/pageDataValue", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", defaultValue = "9999"),
            @ApiImplicitParam(name = "tableName", value = "传感器标识", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间")})
    public Result<?> pageDataValue(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "9999") Integer pageSize,
            @RequestParam String tableName,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime) {
        return vmSensorService.pageDataValue(pageNo, pageSize, tableName, startTime, endTime);
    }

    @ApiOperation(value = "历史数据查询", notes = "历史数据查询")
    @RequestMapping(value = "/sensorDataValue", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableName", value = "传感器标识，多值用“,”分隔", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间")})
    public Result<?> sensorDataValue(@RequestParam String tableName,
                                     @RequestParam(required = false) String startTime,
                                     @RequestParam(required = false) String endTime) {
        return vmSensorService.getDataValue(tableName, startTime, endTime);
    }

    @ApiOperation(value = "查询某一时刻数据", notes = "查询某一时刻数据")
    @RequestMapping(value = "/sensorQueryTime", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableName", value = "传感器标识，多值用“,”分隔", required = true),
            @ApiImplicitParam(name = "dateTime", value = "时间")})
    public Result<?> sensorQueryTime(@RequestParam String tableName,
                                     @RequestParam(required = false) String dateTime) {
        return vmSensorService.sensorQueryTime(tableName, dateTime);
    }

}
